--- title: "L2-013 红色警报" created: 2025-11-28 tags: - 算法 --- # L2-013 红色警报 ## 题目 [L2-013 红色警报](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=994805063963230208&page=1) ![[image-a57e681d.png]] ## 思路分析 ![[image-9620db6d.png]] ## 代码实现 ```cpp #include using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1}; const int inf = 0x3f3f3f3f; const int N=505; bool g[N][N]; bool st[N]; bool banned[N]; int n,m; void bfs(int u){ queue q; q.push(u); st[u]=true; while(!q.empty()){ int t=q.front();q.pop(); for(int v=0;v>n>>m; for(int i=0;i>a>>b; g[a][b]=g[b][a]=true; } int k;cin>>k; int currentBlocks = countBolcks(); for(int i=0;i>city; banned[city]=true; int newBlocks = countBolcks(); if(newBlocks <= currentBlocks){ cout << "City " << city << " is lost." << endl; }else if(newBlocks > currentBlocks){ cout << "Red Alert: City " << city << " is lost!" << endl; } currentBlocks=newBlocks; if(i==n-1){ cout << "Game Over." << endl; } } return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[L2-012 关于堆的判断|L2-012 关于堆的判断]] 🏠 [[00-天梯赛]] ➡️ [[L2-014 列车调度|L2-014 列车调度]]